# Codewisdom Train-Ticket system

REPO=train_ticket
TAG=latest

# build image
.PHONY: build
build: package build-image

.PHONY: package
package:
	@mvn clean package -Dmaven.test.skip=true

.PHONY: build-image
build-image: build
	@find . -type f -name 'Dockerfile' | while read -r dockerfile; do \
		serviceName=$$(echo "$$dockerfile" | cut -d'/' -f2); \
		echo "build $$serviceName image"; \
		docker build -t $(REPO)/$$serviceName:$(TAG) -f $$dockerfile $$(dirname $$dockerfile) ; \
	done

.PHONY: push-image
push-image: build-image
	@find . -type f -name 'Dockerfile' | while read -r dockerfile; do \
		serviceName=$$(echo "$$dockerfile" | cut -d'/' -f2); \
		docker push  $(REPO)/$$serviceName:$(TAG)  \
	done